import java.io.*;
import java.util.Scanner;

//进行普通文件的复制
public class Demo5 {
    public static void main(String[] args) {
        //先输入你要复制文件的路径
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入你要复制文件的路径");
        String url = scan.next();
        //输入你要拷贝的文件路径
        System.out.println("请输入你要拷贝的文件路径");
        String copy = scan.next();
        File file = new File(copy);
        if (!file.isFile()) {
            System.out.println("输入的拷贝的文件路径不对");
            return;
        }
        //进行拷贝
        //读
        try (InputStream file1 = new FileInputStream(url)) {
            //先读取file1之后在复制到file2中
            //写
            try (OutputStream file2 = new FileOutputStream(copy)) {
                byte[] buff = new byte[1024];
                while (true) {
                    int len = file1.read(buff);
                    if (len == -1) {
                        //读到文件末尾
                        break;
                    }
                    file2.write(buff, 0, len);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
